home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / laptop-mode-tools / modules / wireless-iwl-power < prev    next >
Encoding:
Text File  |  2012-05-20  |  3.5 KB  |  106 lines

  1. #! /bin/sh
  2. # Laptop mode tools module, called from /usr/sbin/laptop_mode.
  3. # Configuration in /etc/laptop-mode/conf.d/wireless-iwl-power.conf.
  4. #
  5. # PURPOSE: power saving for the Intel 3945 and 4965 adapters when using the
  6. #          iwlwifi drivers.
  7. #
  8. # This script relies upon the name of the driver.
  9. #
  10.  
  11. #
  12. # Find all the wireless devices using the supplied driver names.
  13. # Place the interface names on the list WIFI_IFNAMES.
  14. #
  15. findWifiIfsByDriver () {
  16.     local DEVICE;
  17.     local LINK_TARGET;
  18.     local ENABLED;
  19.  
  20.     for DEVICE in /sys/class/net/*; do
  21.         if [ -d $DEVICE/wireless -a -h $DEVICE/device/driver ]; then
  22.             # See if the driver for $DEVICE matches the supplied one by checking the link to
  23.             # the driver.
  24.             LINK_TARGET=`readlink $DEVICE/device/driver`
  25.             LINK_TARGET=${LINK_TARGET##*/}
  26.             ENABLED=`cat $DEVICE/device/enable` 
  27.             
  28.             if [ $ENABLED -eq 1 -a "$LINK_TARGET" = "$1" ] ; then
  29.                 # add the interface name to the list
  30.                 WIFI_IFNAMES="$WIFI_IFNAMES ${DEVICE##*/}"
  31.                         else
  32.                                 log "VERBOSE" "$DEVICE doesn't seem to be enabled. Radio Switched off?";
  33.             fi
  34.                 else
  35.                         # LP: #369113
  36.                         # Kernel's 2.6.29 and above have been reported to be missing
  37.                         # the $DEVICE/wireless folder.
  38.                         dev=`basename $DEVICE`
  39.  
  40.             # Inverting return values, we get "0" for wireless device, 
  41.             # and "1" for non-wireless device.
  42.             ($IWCONFIG $dev 2>&1 | grep -q "no wireless extensions.") && ret=1 || ret=0
  43.                         if [ "$ret" = "0" ]; then
  44.                     # add the interface name to the list
  45.                     WIFI_IFNAMES="$WIFI_IFNAMES ${DEVICE##*/}"
  46.                         fi
  47.         fi
  48.     done
  49. }
  50.  
  51. if [ x$CONTROL_IWL_POWER = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_IWL_POWER = xauto ]; then
  52.     log "VERBOSE" "Setting power levels for iwlwifi wireless interfaces."
  53.  
  54.     # Provide defaults for config file settings
  55.     [ "$IWL_AC_POWER" ]   || IWL_AC_POWER=0
  56.     [ "$IWL_BATT_POWER" ] || IWL_BATT_POWER=3
  57.  
  58.     # find executables
  59.     if [ -x /sbin/iwpriv ] ; then
  60.         IWPRIV=/sbin/iwpriv
  61.     elif [ -x /usr/sbin/iwpriv ] ; then
  62.         IWPRIV=/usr/sbin/iwpriv
  63.     else
  64.         log "VERBOSE" "iwpriv is not installed"
  65.     fi
  66.     if [ -x /sbin/iwconfig ] ; then
  67.         IWCONFIG=/sbin/iwconfig
  68.     elif [ -x /usr/sbin/iwconfig ] ; then
  69.         IWCONFIG=/usr/sbin/iwconfig
  70.     else
  71.         log "VERBOSE" "iwconfig is not installed"
  72.     fi
  73.  
  74.     WIFI_IFNAMES=""
  75.     [ -d /sys/module/iwl3945 ] && findWifiIfsByDriver iwl3945
  76.     [ -d /sys/module/iwl4965 ] && findWifiIfsByDriver iwl4965
  77.     [ -d /sys/module/iwlagn ] && findWifiIfsByDriver iwlagn
  78.     for IF in $WIFI_IFNAMES ; do
  79.         if [ $ON_AC -eq 1 ] ; then
  80.             log "VERBOSE" "On AC power: setting power level for $IF to $IWL_AC_POWER."
  81.             if [ -f /sys/class/net/$IF/device/power_level ]; then
  82.                 echo $IWL_AC_POWER > /sys/class/net/$IF/device/power_level;
  83.                 log "VERBOSE" "Using method echo for power mgmt"
  84.             else
  85.                 # For iwlagn, it is one standard behavior. Not multiple like ipwXXXX
  86.                 # Thus let's just simply exec the command here.
  87.                 $IWCONFIG $IF power off
  88.                 log "VERBOSE" "Using $IWCONFIG for power mgmt"
  89.             fi
  90.         else
  91.             log "VERBOSE" "On battery: setting power level for $IF to $IWL_BATT_POWER."
  92.             if [ -f /sys/class/net/$IF/device/power_level ]; then
  93.                 echo $IWL_BATT_POWER > /sys/class/net/$IF/device/power_level;
  94.                 log "VERBOSE" "Using method echo for power mgmt"
  95.             else
  96.                 $IWCONFIG $IF power on
  97.                 log "VERBOSE" "Using $IWCONFIG for power mgmt"
  98.             fi
  99.         fi
  100.     done
  101. else
  102.     log "VERBOSE" "Intel IWL Wireless power setting is disabled."
  103. fi
  104.  
  105.